﻿using System;
using System.Collections.Generic;
using System.Text;
using Rung.Soft.Jx3Tookit.Addon.AutoPress.Utility;
using System.Runtime.Serialization;

namespace Rung.Soft.Jx3Tookit.Addon.AutoPress.Business
{

    /// <summary>
    /// 行为类型
    /// </summary>
    internal enum ActionType : byte
    {
        /// <summary>
        /// 按键
        /// </summary>
        Key,
        /// <summary>
        /// 延时
        /// </summary>
        Delay
    }

    [Serializable]
    public class SkillAction : ISerializable
    {
        internal ActionType Type;

        /// <summary>
        /// 延迟毫秒数
        /// </summary>
        internal int Delay;

        /// <summary>
        /// 按键
        /// </summary>
        internal HotKey Key;

        public SkillAction(HotKey k)
        {
            this.Type = ActionType.Key;
            this.Key = k;
        }

        public SkillAction(int d)
        {
            this.Type = ActionType.Delay;
            this.Delay = d;
        }

        protected SkillAction(SerializationInfo info, StreamingContext context)
        {
            this.Type = (ActionType)info.GetByte("t");
            this.Delay = info.GetInt32("d");
            this.Key = HotKey.FromByte(info.GetByte("k"));
        }

        public override string ToString()
        {
            if (this.Type == ActionType.Delay)
            {
                return string.Format("延迟：{0}毫秒", this.Delay);
            }
            else if (this.Type == ActionType.Key)
            {
                return string.Format("按键：{0}", this.Key);
            }

            return null;
        }

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            info.AddValue("t", (byte)this.Type);
            info.AddValue("d", this.Delay);
            info.AddValue("k", (null == this.Key) ? 0 : this.Key.ToByte());
        }
    }
}
